<?php
namespace Swiftx\Component\Xml;

class Document extends Node {

    /**
     * 从文件加载
     * @param string $path
     */
    public function loadFile(string $path){
        $this->simpleXMLElement = simplexml_load_file($path);
    }

    /**
     * 根据标签名查找节点
     * @param string $name
     * @return Node[]
     */
    public function getNodeByTagName(string $name):array {
        $result = [];
        foreach ($this->simpleXMLElement->$name as $element)
            $result[] = new Node($element);
        return $result;
    }

}